package com.action;

import com.dto.Chauses;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.service.ChausesService;
import org.apache.struts2.ServletActionContext;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * Created by hxw on 2017-6-6.
 */
public class ChausesAction extends ActionSupport implements ModelDriven<Chauses>{
    @Resource(name = "chausesServiceImpl")
    private ChausesService cs;

    private Chauses chauses=new Chauses();
   public String saveChauses()throws Exception{

       chauses.setDate(new Date());
       System.out.println(chauses);
       System.out.println(cs);
       float sum=0f;
       sum=chauses.getNo1()+chauses.getNo2()+chauses.getNo3()+chauses.getNo4()+chauses.getNo5()+chauses.getNo6()+chauses.getNo7()+chauses.getNo8()+chauses.getNo9()+chauses.getNo10()+chauses.getNo11()+chauses.getNo12();
       System.out.println(sum);
       chauses.setSum(sum);
       String s = cs.saveChauses(chauses);
       return s;
   }

    public String getRecordList(){
        List<Chauses> recordList = cs.getRecordList();
        Iterator it=recordList.iterator();
        System.out.println("记录如下：");
        while (it.hasNext()){
            Chauses c= (Chauses) it.next();
            System.out.println(c);
        }
       ServletActionContext.getRequest().setAttribute("recordlist",recordList);
        ActionContext.getContext().put("recordlist",recordList);
        return "recordlist";
    }


    @Override
    public Chauses getModel() {
        return chauses;
    }
}
